<?php
class sms_controller_admin_sms extends AdminController {
	private $obj = '';

	/**
	 * 短消息列表
	 * Enter description here ...
	 */
	public function list_action(){
		$this->obj = Model::factory('sms_model_data');
		$uid = _('uid');
		$starttime = _('start','');
		$endtime = _('end','');
		$page = _('page',1);
		$type = _('type');
		$delete = _('delete');
		$ret = $this->obj->getSmsList($uid,$page,$pageSize=20,$type,$starttime,$endtime,$delete);
		$pages = $this->genPages($ret['INFO'],array('uid'=>_('uid',''),'type'=>_('type'),'start'=>_('start',''),'end'=>_('end',''),'delete'=>_('delete')),true);
		$this->ret = self::success(array('ret'=>$ret, 'pages'=>$pages));
		$this->view = 'list';
	}
	
	public function statistic_list_action(){
		$this->obj = Model::factory('sms_model_data');
		$page = _('page',1);
		$para = array(
				'uid' =>_('uid'),
				'min' =>_('min'),
				'max' =>_('max'),
				'start_day' => _('start'),
				'end_day' =>_('end')
			);
//		$total = '';
		$ret = $this->obj->getSmsStatistic($para,$page,20);
		$pages = $this->genPages($ret['INFO'],array('uid'=>_('uid'),'min'=>_('min'),'max'=>_('max'),'start'=>_('start'),'end'=>_('end')),true);
		$this->ret = self::success(array('ret'=>$ret, 'pages'=>$pages));
		$this->view = 'statistic_list';
	}
	
	public function daily_list_action(){
		$this->obj = Model::factory('sms_model_data');
		$page = _('page',1);
		$para = array(
				'min' =>_('min'),
				'max' =>_('max'),
				'start_day' => _('start'),
				'end_day' =>_('end')
			);
		$total = '';
		$ret = $this->obj->getSmsStatistic_daily($para,$page,20,false,$total);
		$pages = $this->genPages($ret['INFO'],array('min'=>_('min'),'max'=>_('max'),'start'=>_('start'),'end'=>_('end')),true);
		$this->ret = self::success(array('ret'=>$ret, 'pages'=>$pages,'total'=>$total));
		$this->view = 'daily_list';
	}

	public function edit_form_action(){
		$sms_id = _('id','');
		$this->obj = Model::factory('sms_model_data');
		if($sms_id){
			$this->ret = $this->obj->select($sms_id);
		}
		$this->view = 'edit_form';
		
	}
	/**
	 * 删除短信
	 * Enter description here ...
	 */
	public function delete_action(){
		$this->obj = Model::factory('sms_model_data');
		$sms_id = _('id','');
		$uid = _('uid','');
		$flag = _('del',0)==1?true:false;
		$rtype = _('rtype',0);
		$this->ret = self::success($this->obj->invalidSmsById($sms_id,$uid,$flag));
		admin_util_operate::add_operater_log(explode(',',$sms_id), AdminConsts::RES_SMS, AdminConsts::OPR_DEL);
		if($rtype==1){
			$this->_renderJson();
		}else 
			$this->_renderRedirect();
	}
	
	/**
	 * 恢复被删除的短信
	 * Enter description here ...
	 */
	public function resume_action(){
		$sms_id = _('id','');
		$rtype = _('rtype',0);
		$this->obj = Model::factory('sms_model_data');
		$this->ret = self::success($this->obj->resumeSms($sms_id));
		admin_util_operate::add_operater_log(explode(',',$sms_id), AdminConsts::RES_SMS, AdminConsts::OPR_VALID);
		if($rtype==1){
			$this->_renderJson();
		}else 
			$this->_renderRedirect();
	}

	
	/**
	 * 审核短信
	 * Enter description here ...
	 */
	public function verify_action(){
		$this->obj = Model::factory('sms_model_data');
		$sms_id = _('id','');
		$uid = _('uid','');
		$rtype = _('rtype');
		$refuseid = _('refuseid');
		$this->ret = self::success($this->obj->verifySms($sms_id,$uid));
		admin_util_operate::add_operater_log(explode(',',$sms_id), AdminConsts::RES_SMS, AdminConsts::OPR_VERIFY);
		if($refuseid){//删除的短信，
			$this->obj->invalidSmsById($refuseid,$uid,false);
			admin_util_operate::add_operater_log(explode(',',$refuseid), AdminConsts::RES_SMS, AdminConsts::OPR_DEL);
		}
		if($rtype==1){
			$this->_renderJson();
		}else 
			$this->_renderRedirect();
	}
}